package cn.kgc.itrip.service.hotelService;


import cn.kgc.itrip.common.DtoUtil;
import cn.kgc.itrip.common.EmptyUtils;
import cn.kgc.itrip.dto.Dto;
import cn.kgc.itrip.mapper.hotel.HotelMapper;
import cn.kgc.itrip.pojo.*;
import cn.kgc.itrip.vo.ItripAreaDicVO;
import cn.kgc.itrip.vo.ItripImageVO;
import cn.kgc.itrip.vo.hotel.HotelVideoDescVO;
import cn.kgc.itrip.vo.hotel.ItripSearchFacilitiesHotelVO;
import cn.kgc.itrip.vo.hotel.ItripSearchPolicyHotelVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class HotelServiceImpl implements HotelService{


    @Resource
    private HotelMapper hotelMapper;

    /**
     * 热门城市查询
     * @param type
     * @return
     */
    @Override
    public Dto<ItripAreaDicVO> findQueryHotCity(Integer type) {
        //判断是否为空
        if (EmptyUtils.isEmpty(type)){
            return DtoUtil.returnFail("false","10201");
        }
        //如果不为空，则进行搜索
        List<ItripAreaDic> itripAreaDic=hotelMapper.findQueryHotCity(type);
        //创建一个新的list，作为接收值和传回前端
        List<ItripAreaDicVO> itripAreaDicVOS=new ArrayList<>();
        //判断热门城市是否为空
        if (EmptyUtils.isNotEmpty(itripAreaDic)){
            ItripAreaDicVO itripAreaDicVO=null;
            //如果不为空，则进行循环
            for (ItripAreaDic areaDic:itripAreaDic){
                itripAreaDicVO=new ItripAreaDicVO();
                BeanUtils.copyProperties(areaDic,itripAreaDicVO);
                itripAreaDicVOS.add(itripAreaDicVO);
            }
            return DtoUtil.returnDataSuccess(itripAreaDicVOS);
        }
        //如果热门城市为空，则返回false
        return DtoUtil.returnFail("false","10202");
    }

    /**
     * 查询商圈
     * @param cityId
     * @return
     */
    @Override
    public Dto<ItripAreaDicVO> findTradeArea(Integer cityId) {
        //判断是否为空
        if (EmptyUtils.isEmpty(cityId)){
            return DtoUtil.returnFail(" false","10203");
        }
        //如果不为空，则进行搜索
        List<ItripAreaDic> itripAreaDic=hotelMapper.findTradeArea(cityId);
        //创建一个新的list，作为接收值和传回前端
        List<ItripAreaDicVO> itripAreaDicVOS=new ArrayList<>();
        //判断热门城市是否为空
        if (EmptyUtils.isNotEmpty(itripAreaDic)){
            ItripAreaDicVO itripAreaDicVO=null;
            //如果不为空，则进行循环
            for (ItripAreaDic areaDic:itripAreaDic){
                itripAreaDicVO=new ItripAreaDicVO();
                BeanUtils.copyProperties(areaDic,itripAreaDicVO);
                itripAreaDicVOS.add(itripAreaDicVO);
            }
            return DtoUtil.returnDataSuccess(itripAreaDicVOS);
        }
        //如果热门城市为空，则返回false
        return DtoUtil.returnFail("false","10204");
    }

    /**
     * 根据targetId查询酒店图片(type=0)
     * @param targetId
     * @return
     */
    @Override
    public Dto<ItripImageVO> findImgAddress(String targetId) {
        //判断是否为空
        if (EmptyUtils.isEmpty(targetId)){
            return DtoUtil.returnFail("false","100212");
        }
        //如果不为空，则进行搜索
        List<ItripImage> itripImages=hotelMapper.findImgAddress(targetId);
        //创建一个新的list，作为接收值和传回前端
        List<ItripImageVO> itripImageVOS=new ArrayList<>();
        //判断热门城市是否为空
        if (EmptyUtils.isNotEmpty(itripImages)){
            ItripImageVO itripImageVO=null;
            //如果不为空，则进行循环
            for (ItripImage itripImage:itripImages){
                itripImageVO=new ItripImageVO();
                BeanUtils.copyProperties(itripImage,itripImageVOS);
                itripImageVOS.add(itripImageVO);
            }
            return DtoUtil.returnDataSuccess(itripImageVOS);
        }
        return DtoUtil.returnFail("false","100213");
    }

    /**
     * 根据酒店id查询酒店特色、商圈、酒店名称
     * @param hotelId
     * @return
     */
    @Override
    public Dto<HotelVideoDescVO> findVideoDesc(String hotelId) {
        //判断是否为空
        if (EmptyUtils.isEmpty(hotelId)){
            return DtoUtil.returnFail("false","100215");
        }
        //如果不为空，则进行搜索
        HotelVideoDescVO videoDescVO=null;
        //搜索酒店名
        String hotelName=hotelMapper.findHotelName(hotelId);
        videoDescVO.setHotelName(hotelName);
        //搜索商圈
        List<ItripAreaDic> area=hotelMapper.findArea(hotelId);
        for (ItripAreaDic itripAreaDic:area){
            videoDescVO.getTradingAreaNameList().add(itripAreaDic.getName());
        }
        //搜索酒店特色
        List<ItripLabelDic> labelDics=hotelMapper.findLabelDic(hotelId);
        for (ItripLabelDic itripLabelDic:labelDics){
            videoDescVO.getHotelFeatureList().add(itripLabelDic.getDescription());
        }
        if (EmptyUtils.isEmpty(hotelName)||EmptyUtils.isEmpty(area)||EmptyUtils.isEmpty(labelDics)){
            return DtoUtil.returnFail("false","100214");
        }
        return DtoUtil.returnDataSuccess(videoDescVO);
    }

    /**
     * 根据酒店id查询酒店设施
     * @param id
     * @return
     */
    @Override
    public Dto<ItripSearchFacilitiesHotelVO> findFacilitiesHotelVO(Integer id) {
        //判断是否为空
        if (EmptyUtils.isEmpty(id)){
            return DtoUtil.returnFail("false","10206");
        }
        //如果不为空，则进行搜索
        ItripHotel itripHotel=hotelMapper.findFacilitiesHotel(id);
        //判断热门城市是否为空
        if (EmptyUtils.isNotEmpty(itripHotel)){
            ItripSearchFacilitiesHotelVO facilitiesHotelVO=null;
            facilitiesHotelVO.setFacilities(itripHotel.getFacilities());
            return DtoUtil.returnDataSuccess(facilitiesHotelVO);
        }
        return DtoUtil.returnFail("false","10207");
    }

    /**
     * 查询酒店特色列表
     * @return
     */
    @Override
    public Dto fiindHotelFeature() {
        List<String> feature=new ArrayList<>();
        feature=hotelMapper.findFeature();
        if (EmptyUtils.isEmpty(feature)){
            return DtoUtil.returnFail("false","10205");
        }
        return DtoUtil.returnDataSuccess(feature);
    }

    /**
     * 根据酒店id查询酒店特色和介绍
     * @param id
     * @return
     */
    @Override
    public Dto findHotelDetails(Integer id) {
        if (EmptyUtils.isEmpty(id)){
            return DtoUtil.returnFail("false","10210");
        }
        ItripHotel itripHotel=hotelMapper.findHotelDetails(id);
        if (EmptyUtils.isEmpty(itripHotel)){
            return DtoUtil.returnFail("false","10211");
        }
        return DtoUtil.returnDataSuccess(itripHotel);
    }

    /**
     * 根据酒店id查询酒店政策
     * @param id
     * @return
     */
    @Override
    public Dto findHotelPolicy(Integer id) {
        ItripSearchPolicyHotelVO policyHotelVO=null;
        if (EmptyUtils.isEmpty(id)){
            return DtoUtil.returnFail("false","10208");
        }
        ItripHotel itripHotel=hotelMapper.findHotelPolicy(id);
        if (EmptyUtils.isEmpty(itripHotel)){
            return DtoUtil.returnFail("false","10209");
        }
        policyHotelVO.setHotelPolicy(itripHotel.getHotelPolicy());
        return DtoUtil.returnDataSuccess(policyHotelVO);
    }
}
